#include <emscripten/bind.h>

class Counter {
private:
    int count;

public:
    Counter(int initialValue) : count(initialValue) {}

    void increment() {
        count++;
    }

    void decrement() {
        count--;
    }

    int getCount() const {
        return count;
    }

    void reset() {
        count = 0;
    }

    void add(int value) {
        count += value;
    }
};

// 普通函数
std::string greet(const std::string& name) 
{
    return "Hello, " + name + "!";
}

// 使用Embind暴露Counter类到JavaScript
EMSCRIPTEN_BINDINGS(counter_example) {
    emscripten::class_<Counter>("Counter")
        .constructor<int>()
        .function("increment", &Counter::increment)
        .function("decrement", &Counter::decrement)
        .function("getCount", &Counter::getCount)
        .function("reset", &Counter::reset)
        .function("add", &Counter::add);
    

    // 导出greet函数
    emscripten::function("greet", &greet);        
    
}